package com.java.common.lang.enums;

import java.util.HashMap;
import java.util.Map;
import org.springframework.lang.Nullable;

/**
 * 请求方式
 *
 * @author Administrator
 */
public enum HttpMethodEnum {

    /**
     * GET
     */
    GET,

    /**
     * HEAD
     */
    HEAD,

    /**
     * POST
     */
    POST,

    /**
     * PUT
     */
    PUT,

    /**
     * PATCH
     */
    PATCH,

    /**
     * PATCH
     */
    DELETE,

    /**
     * OPTIONS
     */
    OPTIONS,

    /**
     * TRACE
     */
    TRACE;

    private static final Map<String, HttpMethodEnum> MAPPINGS = new HashMap<>(16);

    static {
        for (HttpMethodEnum httpMethod : values()) {
            MAPPINGS.put(httpMethod.name(), httpMethod);
        }
    }

    @Nullable
    public static HttpMethodEnum resolve(@Nullable String method) {
        return (method != null ? MAPPINGS.get(method) : null);
    }

    public boolean matches(String method) {
        return (this == resolve(method));
    }

}